-
Notifications
You must be signed in to change notification settings - Fork 898
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add RBAC for virtual attributes in API #15145
Add RBAC for virtual attributes in API #15145
Conversation
50f0aa3
to
5aaa3c8
Compare
@miq-bot add_label fine/yes, bug, api, rbac |
@@ -205,7 +217,7 @@ def expand_virtual_attributes(json, type, resource) | |||
def fetch_direct_virtual_attribute(type, resource, attr) | |||
return unless attr_accessible?(resource, attr) | |||
virtattr_accessor = virtual_attribute_accessor(type, attr) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure how virtattr_accessor ( send(virtattr_accessor, resource)
is used.
Should it be also in RBAC ? What are examples of using it ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
used by API when it needs extra logic for fetching an attribute, i.e. look at any of the fetch__attr named methods. currently implemented for service_dialogs content and orchestration_stacks stdout, so not traversing relationships and we're already rbac'd on the resource itself, so we're ok with those.
@abellotti Please review when you have some time. |
if resource.class.plural?(attribute) | ||
Rbac.filtered(resource.public_send(attribute)) | ||
else | ||
Rbac.filtered_object(resource).public_send(attribute) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this handle the case where the resource is filtered out due to RBAC?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 I added try
when is the resource is filtered out.
5aaa3c8
to
8c90800
Compare
b2b834e
to
3940718
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
if resource.class.try(:plural?, attribute) | ||
Rbac.filtered(resource.public_send(attribute)) | ||
else | ||
Rbac.filtered_object(resource).try(:public_send, attribute) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is the Rbac.filtered_object(resource) on line 173 needed ? We already did the RBAC on the resource, isn't resource.public_send(attribute) sufficient ? Thanks.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there are no RBAC check where associations are requested thru attributes
params like /api/providers/2?attributes=parent_manager.host, parent_manager.cloud_tenants
we have RBAC check for collections and as you said for resource but not for the ?attributes
@lpichler I'm leaning towards The goal of Is there another place to put this code other than |
3940718
to
77d317a
Compare
Virtual attributes are passed to API thru ‘attributes’ parameter and it can be: - direct association e.g. attributes=vms (plural associations - collection) e.g. attributes=parent_manage (belongs_to association) /api/providers/2?attributes=parent_manages,vms - indirect association e.g. attributes=parent_manager.cloud_tenants (plural associations - collection) e.g. attributes=parent_manager.host (belongs_to association) localhost:3000/api/providers/2?attributes=parent_manager.host, parent_manager.cloud_tenants This RBAC situation is covered by method virtual_attribute_search(resource, attribute) where attribute can be has_many association or belongs_to (There are different RBAC check) it can also pure class as MiqRequestWorkflow (last if-else leg)
77d317a
to
0d479b1
Compare
@miq-bot remove_label wip |
Checked commits lpichler/manageiq@75f0552~...0d479b1 with ruby 2.2.6, rubocop 0.47.1, and haml-lint 0.20.0 |
Thanks for the review.
@kbrock I put it in the method here with the comment and removed it from @gtanzillo @abellotti |
Add RBAC for virtual attributes in API (cherry picked from commit bec2d7a) https://bugzilla.redhat.com/show_bug.cgi?id=1452868
Fine backport details:
|
So called virtual attributes are passed to API thru ‘attributes’ parameter and such attributes can be:
e.g. attributes=vms (plural associations - collection)
e.g. attributes=parent_manage (belongs_to association)
/api/providers/2?attributes=parent_manager,vms
e.g. attributes=parent_manager.cloud_tenants (plural associations - collection)
e.g. attributes=parent_manager.host (belongs_to association)
/api/providers/2?attributes=parent_manager.host, parent_manager.cloud_tenants
This RBAC situation is covered by method
virtual_attribute_search(resource, attribute)
where the attribute can be
has_many
association or belongs_to (There are different RBAC check)it can also be for the pure class as
MiqRequestWorkflow
(last if-else leg)Links
Gaprindashvili BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1448857
FINE BZ: https://bugzilla.redhat.com/show_bug.cgi?id=1452868
PR for EUWE: #15143 there were CloudTenants listed in controller, there it is listed by API